package com.itcast.demo;

import com.itcast.domain.Orders;
import com.itcast.mapper.OrdersMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.util.List;

public class Demo01 {
    public static void main(String[] args) throws IOException {
        SqlSessionFactory build = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("sql.xml"));
        SqlSession sqlSession = build.openSession();
        OrdersMapper mapper = sqlSession.getMapper(OrdersMapper.class);
        List<Orders> all = mapper.findAll();
        for (Orders orders : all) {
            System.out.println("orders = " + orders);
            System.out.println("订单编号"+orders.getNumber()

            );
            System.out.println("用户名称" + orders.getUser().getUsername());

        }
        sqlSession.close();
    }
}
